//定时器
//1.一次性定时器，是global下的成员方法
/*
var timer = null;
timer = global.setTimeout(()=>{
  console.log('setTimeout...');
},2000);
//清除一次性定时器
clearTimeout(timer);
*/
//2.周期性定时器
/*
var timer = null;
timer = setInterval(()=>{
  console.log('setInterval...');
},2000);
//清除周期性定时器
clearInterval(timer);
*/

//练习：创建周期性定时器，打印10次'hello world'后，清除定时器。
/*
var n = 0;
var timer = null;
timer = setInterval(()=>{
  n++; 
  //n和10
  if(n == 10){
	clearInterval(timer);
  }
  console.log(`hello world--${n}`);
},2000);
*/
//3.nextTick
/*
console.log(1)
process.nextTick(()=>{
  console.log(2);
});
console.log(3);
*/
//4.setImmediate
console.log(1);
var timer = null;
timer = setImmediate(()=>{
  console.log(2);
});
clearImmediate(timer);
console.log(3);






